import com.StuAB;
import com.Student;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.util.List;


/**
 * Created by webrx on 2017/6/10.
 */
public class Dom {
    @Test
    public void  aa() throws IOException {
        SqlSessionFactory aq= new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader("mybatis-config.xml"));
        aq.getConfiguration().addMapper(StuAB.class);

        SqlSession session = aq.openSession();

        StuAB sdao = session.getMapper(StuAB.class);
        Student stu = new Student();
        stu.setId(155);
        stu.setName("大家");
        sdao.insert(stu);
        //查询显示数据
        List<Student> list = sdao.queryAll();
        for(Student st : list){
            System.out.println(st.getName());
        }
        session.close();

    }
}
